/**
 * hujun -用户管理 2017-12-22
 */
define([
  './themes/lang/' + window.YUFP_SYS_CONFIG.language + '/pages/content/systemManager/userInfoManager/sysUserManager.js',
  './custom/widgets/js/yufpOrgTree.js',
  './custom/widgets/js/yufpRoleSelector.js',
  './libs/jsencrypt/jsencrypt.min.js',
  './custom/widgets/js/yufpDptTree.js',
  './custom/widgets/js/yufpExtTree.js'
], function (require, exports) {
  yufp.lookup.reg('DATA_STS,SEX_TYPE,IDENT_TYPE,HIGHEST_EDU,RANK_LEVEL');
  // page加载完成后调用ready方法
  exports.ready = function (hashCode, data, cite) {
    var stsKeyValue = null;
	
    yufp.custom.vue({
      el: '#userInfo',
      data: function () {
        var em = this;
        return {
          formdata: {
			 
		  }, // 搜索表单绑定
          addUserButton: !yufp.session.checkCtrl('addUser'), // 新增按钮控制
          editUserButton: !yufp.session.checkCtrl('updateUser'), // 修改按钮控制
          deleteUserButton: !yufp.session.checkCtrl('deleteUser'), // 删除按钮控制
          useUserButton: !yufp.session.checkCtrl('useUser'), // 启用按钮控制
          unuseUserButton: !yufp.session.checkCtrl('unuseUser'), // 停用按钮控制
          userRelButton: !yufp.session.checkCtrl('userRel'), // 用户管理信息按钮控制
          resetPwsButton: !yufp.session.checkCtrl('resetPwsUser'), // 密码重置按钮控制
          height: yufp.custom.viewSize().height - 150,
          heightOrg: yufp.custom.viewSize().height - 120,
          heightOt: yufp.custom.viewSize().height - 200,
          dataRoot: { orgId: yufp.session.org.id, orgName: yufp.session.org.name },
          dataParams: { orgSts: 'A', lazy: true },
          treeUrlRel: backend.appOcaService + '/api/adminsmorg/orgtreequery',
          uploadAction: yufp.service.getUrl({ url: backend.gatewayService + backend.fileService + '/api/file/provider/uploadfile?access_token=' + yufp.service.getToken() }),
          userIdInfo: null,
          datePick: {// 限制不可小于当前日期
            disabledDate: function (time) {
              return time.getTime() < Date.now() - 8.64e7;
            }
          },
          datePick2: {// 限制不可大于当前日期
            disabledDate: function (time) {
              return time.getTime() > Date.now() - 8.64e6;
            }
          },
          orgRootId: yufp.session.org.code, // 根据节点ID
          dialogVisibleImage: false,
          userForm: {
            userName: '',
            loginCode: '',
            deadline: '',
            userSts: '',
            userAvatar: ''

          },
          infoOrgId: '',
          mainGrid: {
            query: {
              userInfo: '',
              orgId: ''
            },
            height: yufp.custom.viewSize().height - 200,
            checkbox: true,
            dataUrl: backend.appOcaService + '/api/adminsmuser/querypage',
            paging: {
              page: 1,
              size: 10
            },
            currentRow: null,
            dataParams: {
              condition: JSON.stringify({
                orgId: yufp.session.org.id
              })
            },
            tableColumns: [
              { label: this.$t('sysUserManager.xh'), width: '50', resizable: true, type: 'index' },
              {
                label: this.$t('sysUserManager.yhmc'),
                prop: 'userName',
				width: '130',
                resizable: true,
                template: function () {
                  return '<template scope="scope">\
                                <a onclick="return false;" href="javascipt:void(0);" style="text-decoration:underline;" @click="_$event(\'custom-detail-click\', scope)">{{ scope.row.userName }}</a>\
                            </template>\
							';
                }
              },
			  {//新增用户名称英文
			    label: this.$t('sysUserManager.yhmcEn'),
			    prop: 'userName',
			  	width: '130',
			    resizable: true,
			    template: function () {
			      return '<template scope="scope">\
			                    <a onclick="return false;" href="javascipt:void(0);" style="text-decoration:underline;" @click="_$event(\'custom-detail-click\', scope)">{{ scope.row.userNameEn }}</a>\
			                </template>\
			  							';
			    }
			  },
			  {//新增用户名称繁体
			    label: this.$t('sysUserManager.yhmcFt'),
			    prop: 'userName',
			  	width: '130',
			    resizable: true,
			    template: function () {
			      return '<template scope="scope">\
			                    <a onclick="return false;" href="javascipt:void(0);" style="text-decoration:underline;" @click="_$event(\'custom-detail-click\', scope)">{{ scope.row.userNameFt }}</a>\
			                </template>\
			  							';
			    }
			  },
              { label: this.$t('sysUserManager.dldm'), prop: 'loginCode', resizable: true},
              // { label: this.$t('sysUserManager.ssbm'), prop: 'dptName', resizable: true, width: '130' },
              { label: this.$t('sysUserManager.zt'), prop: 'userSts', resizable: true, dataCode: 'DATA_STS' },
              { label: this.$t('sysUserManager.xb'), prop: 'userSex', resizable: true, dataCode: 'SEX_TYPE' },
              { label: this.$t('sysUserManager.ygh'), prop: 'userCode', resizable: true },
              { label: this.$t('sysUserManager.yxq'), prop: 'deadline', resizable: true},
              { label: this.$t('sysUserManager.zxbgyh'), prop: 'lastChgName', resizable: true },
              // { label: this.$t('sysUserManager.zxbgsj'), prop: 'lastChgDt', type: 'date', resizable: true, width: '130' }
            ]
          },
          userFields: [{
            columnCount: 2,
            fields: [
              // {//所属机构
              //   field: 'orgId',
              //   label: this.$t('sysUserManager.ssjg'),
              //   type: 'custom',
              //   is: 'yufp-org-tree',
              //   params: {
              //     dataUrl: backend.appOcaService + '/api/adminsmorg/orgtreequery',
              //     lazy: true,
              //     needCheckbox: false,
              //     dataRoot: { orgId: yufp.session.org.id, orgName: yufp.session.org.name },
              //     dataParams: { 'orgSts': 'A', lazy: true }
              //   },
              //   rules: [
              //     { required: true, message: this.$t('sysUserManager.btx'), trigger: 'change' }
              //   ],
              //   selectFn: function (code, data, arry) {
              //     var temp = yufp.clone(em.userFields[0].fields[1].params);
              //     temp.dataParams = {
              //       orgCode: code
              //     };
              //     em.userFields[0].fields[1].params = yufp.clone(temp);
              //   }
              // },
              /* {
                field: 'dptId',
                label: this.$t('sysUserManager.ssbm'),
                type: 'custom',
                is: 'yufp-dpt-tree',
                params: {
                  dataUrl: backend.appOcaService + '/api/util/getdpt',
                  dataId: 'orgCode',
                  needCheckbox: false
                },
                selectFn: function (code, data, arry) {
                }
              }, */
              {
                field: 'userPassword',
                label: this.$t('sysUserManager.mm'),
                type: 'password',
                rules: [
                  { required: true, message: this.$t('sysUserManager.btx'), trigger: 'change' },
                  { max: 100, message: this.$t('sysUserManager.zdcdbcggzf'), trigger: 'blur' }
                ]
              },
              {
                field: 'userPassword1',
                label: this.$t('sysUserManager.qrmm'),
                type: 'password',
                rules: [
                  { required: true, message: this.$t('sysUserManager.btx'), trigger: 'change' },
                  { max: 100, message: this.$t('sysUserManager.zdcdbcggzf'), trigger: 'blur' }
                ]
              }

            ]
          }],
          userOtherFields: [{
            columnCount: 2,
            fields: [
              {
                label: this.$t('sysUserManager.xb'),
                field: 'userSex',
                type: 'radio',
                dataCode: 'SEX_TYPE',
                change: function (model, val, e) {
                }
              },
              {
                field: 'userBirthday',
                label: this.$t('sysUserManager.sr'),
                type: 'date',
                format: 'yyyy-MM-dd',
                pickerOptions: em.datePick2
              },
              /* { field: 'certType', label: this.$t('sysUserManager.zjlx'), type: 'select', dataCode: 'IDENT_TYPE' },
              {
                field: 'certNo',
                label: this.$t('sysUserManager.zjhm'),
                rules: [
                  { validator: yufp.validator.IDCard, message: this.$t('sysUserManager.qsrzqxx'), trigger: 'blur' }
                ]
              }, */
              {
                field: 'userCode',
                label: this.$t('sysUserManager.ygh'),
                rules: [
                  { max: 100, message: this.$t('sysUserManager.zdcdbcggzf'), trigger: 'blur' }
                ]
              },
              {
                field: 'userEmail',
                label: this.$t('sysUserManager.yx'),
                rules: [
                  { validator: yufp.validator.email, message: this.$t('sysUserManager.qsrzqxx'), trigger: 'blur' }
                ]
              },
              {
                field: 'userMobilephone',
                label: this.$t('sysUserManager.yddh'),
                rules: [
                  { validator: yufp.validator.mobile, message: this.$t('sysUserManager.qsrzqxx'), trigger: 'blur' }
                ]
              },
              {
                field: 'userOfficetel',
                label: this.$t('sysUserManager.bgdh'),
                rules: [
                  { validator: yufp.validator.telephone, message: this.$t('sysUserManager.qsrzqxx'), trigger: 'blur' }
                ]
              },
              { field: 'userEducation', label: this.$t('sysUserManager.zgxl'), type: 'select', dataCode: 'HIGHEST_EDU' },
              { field: 'positionDegree', label: this.$t('sysUserManager.zj'), type: 'select', dataCode: 'RANK_LEVEL' },
              {
                field: 'userCertificate',
                label: this.$t('sysUserManager.zgzs'),
                rules: [
                  { max: 200, message: this.$t('sysUserManager.zdcdbcggzf'), trigger: 'blur' }
                ]
              },
              { field: 'entrantsDate', label: this.$t('sysUserManager.rzsj'), type: 'date', format: 'yyyy-MM-dd' },
              {
                field: 'financialJobTime',
                label: this.$t('sysUserManager.cysj'),
                rules: [
                  { validator: yufp.validator.number, message: this.$t('sysUserManager.qsrzqxx'), trigger: 'blur' },
                  { max: 20, message: this.$t('sysUserManager.zdcdbcggzf'), trigger: 'blur' }
                ]
              },
              {
                field: 'positionTime',
                label: this.$t('sysUserManager.renzsj'),
                rules: [
                  { validator: yufp.validator.number, message: this.$t('sysUserManager.qsrzqxx'), trigger: 'blur' },
                  { max: 20, message: this.$t('sysUserManager.zdcdbcggzf'), trigger: 'blur' }
                ]
              },
              {
                field: 'offenIp',
                label: this.$t('sysUserManager.cy'),
                rules: [
                  { validator: yufp.validator.ip, message: this.$t('sysUserManager.qsrzqxx'), trigger: 'blur' }
                ]
              },
              { field: 'lastChgUsr', label: this.$t('sysUserManager.zjgxr'), hidden: true },
              { field: 'lastChgDt', label: this.$t('sysUserManager.zjgxsj'), hidden: true }

            ]
          }],
          userDetailFields: [{
            columnCount: 2,
            fields: [
              { field: 'orgId', label: this.$t('sysUserManager.ssjg'), type: 'custom', is: 'yufp-org-tree' },
              { field: 'dptName', label: this.$t('sysUserManager.ssbm') }
            ]
          }],
          userDetailOtherFields: [{
            columnCount: 2,
            fields: [
              {
                label: this.$t('sysUserManager.xb'),
                field: 'userSex',
                type: 'radio',
                dataCode: 'SEX_TYPE',
                change: function (model, val) {
                }
              },
              { field: 'userBirthday', label: this.$t('sysUserManager.sr'), type: 'date', format: 'yyyy-MM-dd' },
              { field: 'certType', label: this.$t('sysUserManager.zjlx'), type: 'select', dataCode: 'IDENT_TYPE' },
              { field: 'certNo', label: this.$t('sysUserManager.zjhm') },
              { field: 'userCode', label: this.$t('sysUserManager.ygh') },
              { field: 'userEmail', label: this.$t('sysUserManager.yx') },
              { field: 'userMobilephone', label: this.$t('sysUserManager.yddh') },
              { field: 'userOfficetel', label: this.$t('sysUserManager.bgdh') },
              { field: 'userEducation', label: this.$t('sysUserManager.zgxl'), type: 'select', dataCode: 'HIGHEST_EDU' },
              { field: 'positionDegree', label: this.$t('sysUserManager.zj'), type: 'select', dataCode: 'RANK_LEVEL' },
              { field: 'userCertificate', label: this.$t('sysUserManager.zgzs') },
              { field: 'entrantsDate', label: this.$t('sysUserManager.rzsj'), type: 'date', format: 'yyyy-MM-dd' },
              { field: 'financialJobTime', label: this.$t('sysUserManager.cysj') },
              { field: 'positionTime', label: this.$t('sysUserManager.renzsj') },
              { field: 'offenIp', label: this.$t('sysUserManager.cy') },
              { label: this.$t('sysUserManager.zxbgyh'), field: 'lastChgName' },
              { label: this.$t('sysUserManager.zxbgsj'), field: 'lastChgDt', type: 'date', format: 'yyyy-MM-dd' }

            ]
          }],
          activeFlag: 'first',
          mainGridRole: {
            height: 270,
            checkbox: true,
            dataUrl: backend.appOcaService + '/api/adminsmuser/querybyrolests',
            tableColumns: [
              { label: this.$t('sysUserManager.jsdm'), prop: 'roleCode', width: 140, resizable: true },
              { label: this.$t('sysUserManager.jsmc'), prop: 'roleName', width: 150, resizable: true }
            ]
          },
          mainGridPost: {
            height: 270,
            ifDuty: false,
            checkbox: true,
            dataUrl: backend.appOcaService + '/api/adminsmuser/querybyduty',
            tableColumns: [
              { label: this.$t('sysUserManager.gwdm'), prop: 'dutyCde', width: 140, resizable: true },
              { label: this.$t('sysUserManager.gwmc'), prop: 'dutyName', width: 150, resizable: true }
            ]
          },
          stsOptions: null,
          dialogFormVisible: false, // 新增，修改页面是否显示
          dialogDetailVisible: false, // 详情页面是否显示
          nowNode: '', // 当前选中节点数据
          rootId: 'root', // 根节点ID
          rootName: '组织机构树', // 根节点名称
          dialogStatus: '',
          readonly: false, // 维护信息是否只读
          dialogVisibleRelInfo: false, // 用户关联信息是否显示
          dialogVisibleRole: false, // 用户角色是否显示
          activeName: ['1'], // 默认显示name为1的
          rules: {
            userName: [
              { required: true, message: this.$t('sysUserManager.btx'), trigger: 'blur' },
              { max: 100, message: this.$t('sysUserManager.zdcdbcggzf'), trigger: 'blur' }
            ],
            loginCode: [
              { required: true, message: this.$t('sysUserManager.btx'), trigger: 'blur' },
              { max: 100, message: this.$t('sysUserManager.zdcdbcggzf'), trigger: 'blur' }
            ]
          },
          textMap: {
            update: this.$t('sysUserManager.xg'),
            create: this.$t('sysUserManager.xz'),
            detail: this.$t('sysUserManager.xq'),
            relInfo: this.$t('sysUserManager.yhglxx'),
            role: this.$t('sysUserManager.yhjs')
          },
          pwdform: {
            dialogVisible: false,
            pwdFields: [{
              columnCount: 1,
              fields: [{
                field: 'password',
                label: this.$t('sysUserManager.mm'),
                type: 'password',
                rules: [{ required: true, message: this.$t('sysUserManager.btx'), trigger: 'blur' }]
              }, {
                field: 'confirmPwd',
                label: this.$t('sysUserManager.qrmm'),
                type: 'password',
                rules: [{ required: true, message: this.$t('sysUserManager.btx'), trigger: 'blur' }]
              }]
            }],
            pwdButtons: [],
            tempUserId: yufp.session.userId
          },
          imageUrl: ''
        };
      },
      filters: {
        statusFilter: function (status) {
          return stsKeyValue[status];
        }
      },
      methods: {
        handleAvatarSuccess: function (res, file) {
          var url = yufp.settings.ssl ? 'https://' : 'http://';
          url += yufp.settings.url;
          url += backend.fileService;
          url += '/api/file/provider/download?fileId=' + res.data.filePath;
          this.userForm.userAvatar = res.data.filePath;
          this.imageUrl = yufp.util.addTokenInfo(url);
        },
        beforeAvatarUpload: function (file) {
          var type = file.type;
          var size = file.size / 1024 / 1024;
          if (type !== 'image/jpeg' && type !== 'image/png' && type !== 'image/jpg') {
            this.$message.error(this.$t('sysUserManager.sctxtpznsgs'));
          }
          if (size > 2) {
            this.$message.error(this.$t('sysUserManager.sctxtpdxbncg'));
          }
          return type && size;
        },
        queryMainGridFn: function () {
          var me = this;
          var param = {
            condition: JSON.stringify({
              userInfo: this.mainGrid.query.userInfo ? this.mainGrid.query.userInfo : null,
              userSts: this.mainGrid.query.userSts ? this.mainGrid.query.userSts : null,
              deadline: this.mainGrid.query.deadline ? this.mainGrid.query.deadline : null,
              orgId: this.mainGrid.query.orgId ? this.mainGrid.query.orgId : yufp.session.org.id
            })
          };
          me.$refs.mytable.remoteData(param);
        },
        nodeClickFn: function (node, obj, nodeComp) {
          if (node != '') {
            this.nowNode = node;
            /* 初始化部门数据*/
            var temp = yufp.clone(this.userFields[0].fields[1].params);
            temp.dataParams = {
              orgCode: node.orgId
            };
            this.userFields[0].fields[1].params = yufp.clone(temp);
            this.mainGrid.query.orgId = node.orgCode;
            this.mainGrid.query.orgType = node.orgType;
            this.queryMainGridFn();
          }
        },
        openCreateFn: function () {//新增
          this.dialogStatus = 'create';//新增
          this.activeName = ['1'];
          this.dialogFormVisible = true;
          this.dialogDetailVisible = false;
          this.readonly = false;
          this.$nextTick(function () {
            this.$refs.userInfo.resetFields();
            this.$refs.userOtherInfo.resetFields();
            this.userForm = {
              userName: '',
              loginCode: '',
              userSts: 'A',
              deadline: '',
              userAvatar: ''
            };
            this.$refs.userInfo.formModel.lastChgUsr = yufp.session.userId;
            this.$refs.userInfo.formModel.userSts = 'A';
            if (this.nowNode != null) {
              this.$refs.userInfo.formModel.orgId = this.nowNode.orgId;
            }
            this.userOtherFields[0].fields[1].pickerOptions = this.datePick2;
            this.userFields[0].fields[2].hidden = false;
            this.userFields[0].fields[3].hidden = false;
            // 初始化部门树
            var temp = yufp.clone(this.userFields[0].fields[1].params);
            if (this.nowNode == null) {
              temp.dataParams = {
                orgCode: yufp.session.org.code
              };
            } else {
              temp.dataParams = {
                orgCode: this.nowNode.orgId
              };
            }
            this.userFields[0].fields[1].params = yufp.clone(temp);
          });
        },
        openDetailFn: function (row) {
          var url = yufp.settings.ssl ? 'https://' : 'http://';
          url += yufp.settings.url;
          url += backend.fileService;
          url += '/api/file/provider/download?fileId=' + row.row.userAvatar;
          this.imageUrl = yufp.util.addTokenInfo(url);
          this.mainGrid.currentRow = row;
          this.activeName = ['1', '2'];
          this.dialogFormVisible = false;
          this.dialogDetailVisible = true;
          this.userForm = {
            userName: row.row.userName,
            loginCode: row.row.loginCode,
            userSts: row.row.userSts ? row.row.userSts : null,
            deadline: row.row.deadline ? row.row.deadline : null,
            userAvatar: row.row.userAvatar ? row.row.userAvatar : null
          };
          this.$nextTick(function () {
            this.$refs.userDetailInfo.resetFields();
            this.$refs.userDetailOtherInfo.resetFields();
            yufp.extend(this.$refs.userDetailInfo.formModel, row.row);
            yufp.extend(this.$refs.userDetailOtherInfo.formModel, row.row);
          });
        },
        openEditFn: function (row) {
          var me = this;
          if (this.$refs.mytable.selections.length !== 1) {
            this.$message({ message: this.$t('sysUserManager.qxxzytjl'), type: 'warning' });
            return;
          }
          var row = this.$refs.mytable.selections[0];
          if (row.userSts === 'A') {
            this.$message({ message: this.$t('sysUserManager.znxzsxhzdsxdsj'), type: 'warning' });
            return;
          }
          var url = yufp.settings.ssl ? 'https://' : 'http://';
          url += yufp.settings.url;
          url += backend.fileService;
          url += '/api/file/provider/download?fileId=' + row.userAvatar;
          this.imageUrl = yufp.util.addTokenInfo(url);
          this.dialogStatus = 'update';
          this.activeName = ['1'];
          this.dialogFormVisible = true;
          this.dialogDetailVisible = false;
          this.readonly = true;
          this.userForm = {
            userName: row.userName,
            loginCode: row.loginCode,
            userSts: row.userSts ? row.userSts : null,
            deadline: row.deadline ? row.deadline : null,
            userAvatar: row.userAvatar ? row.userAvatar : null
          };

          this.$nextTick(function () {
            this.$refs.userInfo.resetFields();
            this.$refs.userOtherInfo.resetFields();
            var userOtherFieldsData = me.userOtherFields[0].fields;
            var userFieldsData = me.userFields[0].fields;
            var rowData1 = {};
            var rowData2 = {};
            rowData1 = me.filterData(row, userFieldsData);
            rowData1.userId = row.userId;
            rowData2 = me.filterData(row, userOtherFieldsData);
            yufp.extend(this.$refs.userInfo.formModel, rowData1);
            yufp.extend(this.$refs.userOtherInfo.formModel, rowData2);
            // 初始化部门树
            var temp = yufp.clone(this.userFields[0].fields[1].params);

            temp.dataParams = {
              orgCode: row.orgId
            };
            this.userFields[0].fields[1].params = yufp.clone(temp);
            this.userFields[0].fields[2].hidden = true;
            this.userFields[0].fields[3].hidden = true;
            this.userOtherFields[0].fields[1].pickerOptions = this.datePick2;
          });
        },
        filterData: function (obj, arr) {
          var resultObj = {};
          for (var key in obj) {
            for (var i = 0; i < arr.length; i++) {
              if (key == arr[i].field) {
                resultObj[key] = obj[key];
                continue;
              }
            }
          }
          return resultObj;
        },
        openRoleFn: function () {

        },
        openRelInfoFn: function () {
          var row = this.$refs.mytable.selections;
          if (row.length != 1) {
            this.$message({ message: this.$t('sysUserManager.qxzytsj'), type: 'warning' });
            return;
          }
          this.dialogStatus = 'relInfo';
          this.dialogVisibleRelInfo = true;
          this.mainGridPost.ifDuty = true;
          this.activeFlag = 'first';
          var em = this;
          this.$nextTick(function () {
            em.$refs.roleTable.remoteData({ orgId: row[0].orgId });
            // em.$refs.dutyTable.remoteData({ orgId: row[0].orgId });
            var param = {
              condition: JSON.stringify({
                paramId: row[0].userId
              }),
              page: 1,
              size: 10000
            };
            yufp.service.request({
              method: 'GET',
              url: backend.appOcaService + '/api/adminsmuser/queryuserrole',
              data: param,
              callback: function (code, message, response) {
                var infos = response.data;
                var it = 0, total = 100;
                var fn = function () {
                  if (total < 1 || em.$refs.roleTable.data.length > 0) {
                    clearInterval(it);
                    for (var i = 0; i < infos.length; i++) {
                      em.$refs.roleTable.data.filter(function (item) {
                        if (item.roleId === infos[i].roleId) {
                          em.$refs.roleTable.toggleRowSelection(item);
                        }
                      });
                    }
                  } else {
                    total--;
                  }
                };
                var it = setInterval(fn, 50);
              }
            });
          });
        },
        saveCreateFn: function () {
          var me = this;
          var userInfo = me.$refs.userInfo, userOtherInfo = me.$refs.userOtherInfo;
          var infoValid = true;
          var otherInfoValid = true;
          var infoValidForm = true;
          me.$refs.userForm.validate(function (valid) {
            infoValidForm = valid;
          });
          userInfo.validate(function (valid) {
            infoValid = valid;
          });
          userOtherInfo.validate(function (valid) {
            otherInfoValid = valid;
          });
          if (infoValidForm && infoValid && otherInfoValid) {
            var comitData = {};
            delete userInfo.formModel.userId;
            if (userInfo.formModel.userPassword !== userInfo.formModel.userPassword1) {
              me.$message({ message: me.$t('sysUserManager.qrmmhmmbyz'), type: 'warning' });
              return false;
            }
            yufp.extend(comitData, userInfo.formModel);
            yufp.extend(comitData, userOtherInfo.formModel);
            yufp.extend(comitData, me.userForm);
            if (comitData.userId) {
              delete comitData.userId;
            }
            comitData.lastChgUsr = yufp.session.userId;
            var encodePwd = this.encodePassword(userInfo.formModel.userPassword);
            yufp.service.request({
              url: backend.uaaService + '/api/passwordcheck/checkpwd',
              method: 'POST',
              data: {
                sysId: yufp.session.logicSys.id,
                pwd: encodePwd,
                userId: '',
                passwordType: '2'
              },
              callback: function (code, message, response) {
                if (code == 0 && response.code === '10100001') {
                  comitData.userPassword = encodePwd;
                  delete comitData.userPassword1;
                  yufp.service.request({
                    method: 'POST',
                    url: backend.appOcaService + '/api/adminsmuser/adduserinfo',
                    data: comitData,
                    callback: function (code, message, response) {
                      if (code == 0 && response.code == 0) {
                        me.dialogFormVisible = false;
                        me.$message({ message: me.$t('sysUserManager.sjbccg') });
                        me.queryMainGridFn();
                      } else {
                        me.$message({ message: response.message, type: 'warning' });
                      }
                    }
                  });
                } else {
                  me.$message({ message: me.$t('sysUserManager.mm') + ':' + response.message, type: 'warning' });
                  return false;
                }
              }
            });
          } else {
            me.$message({ message: me.$t('sysUserManager.qjcsrxsfhf'), type: 'warning' });
            return false;
          }
        },
        saveEditFn: function (form) {
          var me = this;
          var userInfo = me.$refs.userInfo, userOtherInfo = me.$refs.userOtherInfo;
          userInfo.formModel.userPassword1 = userInfo.formModel.userPassword;
          var infoValid = true;
          var otherInfoValid = true;
          var infoValidForm = true;
          me.$refs.userForm.validate(function (valid) {
            infoValidForm = valid;
          });
          userInfo.validate(function (valid) {
            infoValid = valid;
          });
          userOtherInfo.validate(function (valid) {
            otherInfoValid = valid;
          });
          if (infoValidForm && infoValid && otherInfoValid) {
            var users = {
              orgId: userInfo.formModel.orgId,
              dptId: userInfo.formModel.dptId
            };
            var comitData = {};
            yufp.extend(comitData, userInfo.formModel);
            yufp.extend(comitData, userOtherInfo.formModel);
            yufp.extend(comitData, me.userForm);
            yufp.extend(comitData, users);
            comitData.lastChgUsr = yufp.session.userId;
            delete comitData.userPassword1;
            yufp.service.request({
              method: 'POST',
              url: backend.appOcaService + '/api/adminsmuser/update',
              data: comitData,
              callback: function (code, message, response) {
                if (code == 0 && response.code == 0) {
                  me.dialogFormVisible = false;
                  me.$message({ message: me.$t('sysUserManager.sjbccg') });
                  me.queryMainGridFn();
                } else {
                  me.$message({ message: response.message, type: 'warning' });
                }
              }
            });
          } else {
            me.$message({ message: me.$t('sysUserManager.qjcsrxsfhf'), type: 'warning' });
            return false;
          }
        },
        useBatchFn: function () { // 批量启用
          var rows = this.$refs.mytable.selections;
          if (rows.length > 0) {
            var id = '';
            for (var i = 0; i < rows.length; i++) {
              var row = rows[i];
              if (row.userSts === 'I' || row.userSts === 'W') {
                id = id + ',' + row.userId;
              } else {
                this.$message({ message: this.$t('sysUserManager.znxztyhdsxdsj'), type: 'warning' });
                return;
              }
            }
            var vue = this;
            this.$confirm(this.$t('sysUserManager.cczjqygsjsfjx'), this.$t('sysUserManager.ts'), {
              confirmButtonText: this.$t('sysUserManager.qd'),
              cancelButtonText: this.$t('sysUserManager.qx'),
              type: 'warning',
              center: true
            }).then(function () {
              yufp.service.request({
                method: 'POST',
                data: {
                  id: id,
                  userId: yufp.session.userId
                },
                url: backend.appOcaService + '/api/adminsmuser/usebatch?id=' + id + '&userId=' + yufp.session.userId,
                callback: function (code, message, response) {
                  vue.$message({ message: vue.$t('sysUserManager.sjczcg') });
                  vue.queryMainGridFn();
                }
              });
            });
          } else {
            this.$message({ message: this.$t('sysUserManager.qxxzyqydsj'), type: 'warning' });
            return;
          }
        },
        unUseBatchFn: function () { // 批量停用
          var rows = this.$refs.mytable.selections;
          if (rows.length > 0) {
            var id = '';
            for (var i = 0; i < rows.length; i++) {
              var row = rows[i];
              if (row.userSts === 'A') {
                id = id + ',' + row.userId;
              } else {
                this.$message({ message: this.$t('sysUserManager.znxzysxdsj'), type: 'warning' });
                return;
              }
            }

            var vue = this;
            this.$confirm(this.$t('sysUserManager.cczjtygsjsfjx'), this.$t('sysUserManager.ts'), {
              confirmButtonText: this.$t('sysUserManager.qd'),
              cancelButtonText: this.$t('sysUserManager.qx'),
              type: 'warning',
              center: true
            }).then(function () {
              yufp.service.request({
                method: 'POST',
                data: {
                  id: id,
                  userId: yufp.session.userId
                },
                url: backend.appOcaService + '/api/adminsmuser/unusebatch?id=' + id + '&userId=' + yufp.session.userId,
                callback: function (code, message, response) {
                  vue.$message({ message: vue.$t('sysUserManager.sjczcg') });
                  vue.queryMainGridFn();
                }
              });
            });
          } else {
            this.$message({ message: this.$t('sysUserManager.qxxzytydsj'), type: 'warning' });
            return;
          }
        },
        deletestFn: function () { // 批量删除
          var rows = this.$refs.mytable.selections;
          if (rows.length > 0) {
            var id = '';
            for (var i = 0; i < rows.length; i++) {
              var row = rows[i];
              if (row.userSts === 'I') {
                id = id + ',' + row.userId;
              } else {
                this.$message({ message: this.$t('sysUserManager.znsctydsj'), type: 'warning' });
                return;
              }
            }
            var vue = this;
            this.$confirm(this.$t('sysUserManager.cczjyjscgwjsfjx'), this.$t('sysUserManager.ts'), {
              confirmButtonText: this.$t('sysUserManager.qd'),
              cancelButtonText: this.$t('sysUserManager.qx'),
              type: 'warning',
              center: true
            }).then(function () {
              yufp.service.request({
                method: 'POST',
                data: {
                  id: id
                },
                url: backend.appOcaService + '/api/adminsmuser/deletebatch?id=' + id,
                callback: function (code, message, response) {
                  vue.$message({ message: vue.$t('sysUserManager.sjsccg') });
                  vue.queryMainGridFn();
                }
              });
            });
          } else {
            this.$message({ message: this.$t('sysUserManager.qxxzyscdsj'), type: 'warning' });
            return;
          }
        },
        handleClick: function (tab, event) {
          var rows = this.$refs.mytable.selections;
          var em = this;
          var param = {
            condition: JSON.stringify({
              paramId: rows[0].userId
            }),
            page: 1,
            size: 10000
          };
          if (tab.name === 'first') {
            yufp.service.request({
              method: 'GET',
              url: backend.appOcaService + '/api/adminsmuser/queryuserrole',
              data: param,
              callback: function (code, message, response) {
                var infos = response.data;
                for (var i = 0; i < infos.length; i++) {
                  em.$refs.roleTable.data.filter(function (item) {
                    if (item.roleId === infos[i].roleId) {
                      em.$refs.roleTable.toggleRowSelection(item, true);
                    }
                  });
                }
              }
            });
          } else if (tab.name === 'second') {
            yufp.service.request({
              method: 'GET',
              url: backend.appOcaService + '/api/adminsmuser/queryuserduty',
              data: param,
              callback: function (code, message, response) {
                var infos = response.data;
                for (var i = 0; i < infos.length; i++) {
                  em.$refs.dutyTable.data.filter(function (item) {
                    if (item.dutyId === infos[i].dutyId) {
                      em.$refs.dutyTable.toggleRowSelection(item, true);
                    }
                  });
                }
              }
            });
          } else if (tab.name === 'third') {
            yufp.service.request({
              method: 'GET',
              url: backend.appOcaService + '/api/adminsmuser/queryuserorg',
              data: param,
              callback: function (code, message, response) {
                var infos = response.data;
                var keys = [];
                for (var i = 0; i < infos.length; i++) {
                  keys.push(infos[i].orgId);
                }
                em.$refs.orgUsertree.setCheckedKeys(keys, true);
              }
            });
          }
        },
        closeFn: function () {
          this.mainGridPost.ifDuty = false;
        },
        saveEditFnOrg: function () {
          var checks = this.$refs.orgUsertree.getCheckedKeys();
          var em = this;
          var commit = [];
          var row = em.$refs.mytable.selections[0];
          for (var i = 0; i < checks.length; i++) {
            var data = {
              userId: row.userId,
              lastChgUsr: yufp.session.userId,
              orgId: checks[i]
            };
            commit.push(data);
          }
          yufp.service.request({
            method: 'POST',
            url: backend.appOcaService + '/api/adminsmuser/saveorg/' + row.userId,
            data: JSON.stringify(commit),
            callback: function (code, message, response) {
              em.$message({ message: em.$t('sysUserManager.sjczcg') });
            }
          });
        },
        saveEditFnRole: function () {
          var list = this.$refs.roleTable.selections;
          var em = this;
          var commit = [];
          var row = em.$refs.mytable.selections[0];
          for (var i = 0; i < list.length; i++) {
            var data = {
              userId: row.userId,
              lastChgUsr: yufp.session.userId,
              roleId: list[i].roleId
            };
            commit.push(data);
          }
          yufp.service.request({
            method: 'POST',
            url: backend.appOcaService + '/api/adminsmuser/saverole/' + row.userId,
            data: JSON.stringify(commit),
            callback: function (code, message, response) {
              em.$message({ message: em.$t('sysUserManager.sjczcg') });
            }
          });
        },
        saveEditFnPost: function () {
          var list = this.$refs.dutyTable.selections;
          var em = this;
          var commit = [];
          var row = em.$refs.mytable.selections[0];
          for (var i = 0; i < list.length; i++) {
            var data = {
              userId: row.userId,
              lastChgUsr: yufp.session.userId,
              dutyId: list[i].dutyId
            };
            commit.push(data);
          }
          yufp.service.request({
            method: 'POST',
            url: backend.appOcaService + '/api/adminsmuser/savepost/' + row.userId,
            data: JSON.stringify(commit),
            callback: function (code, message, response) {
              em.$message({ message: em.$t('sysUserManager.sjczcg') });
            }
          });
        },
        // 重置密码按钮
        resetPassword: function () {
          if (this.$refs.mytable.selections.length != 1) {
            this.$message(this.$t('sysUserManager.qxzytsj'), this.$t('sysUserManager.ts'));
            return;
          }
          var temp = this.$refs.mytable.selections[0];
          this.pwdform.tempUserId = temp.userId;
          this.pwdform.dialogVisible = true;
          var _this = this;
          _this.$nextTick(function () {
            _this.$refs.pwdform.resetFn();
          });
        },
        // 确认修改密码
        resetPwd: function () {
          var me = this;
          var data = this.$refs.pwdform.formModel;
          var password = data.password;
          var comfirmPwd = data.confirmPwd;
          if (password == null || password == '' || comfirmPwd == null || comfirmPwd == '') {
            this.$message(this.$t('sysUserManager.qsrbtx'), this.$t('sysUserManager.ts'));
            return;
          }

          if (password != comfirmPwd) {
            this.$message(this.$t('sysUserManager.lcsrmmbyz'), this.$t('sysUserManager.ts'));
            return;
          }
          var encodePwd = this.encodePassword(password);
          // me.pwdStrategyCheck(encodePwd);
          yufp.service.request({// 校验新密码是否和旧密码相同
            url: backend.uaaService + '/api/passwordcheck/match',
            method: 'POST',
            data: {
              sysId: this.sysLogicId,
              pwd: encodePwd,
              passwordType: '2',
              userId: me.pwdform.tempUserId
            },
            callback: function (code, message, response) {
              if (code == 0 && response.code == '10100001') {
                me.$message({
                  message: me.$t('sysUserManager.xmmbnhjmmxt'),
                  type: 'warning'
                });
                return;
              } else if (code == 0 && response.code == '10100000') {
                me.pwdStrategyCheck(encodePwd);
              } else {
                me.$message({
                  message: me.$t('sysUserManager.mmxgsbqzs'),
                  type: 'warning'
                });
              }
            }
          });
        },
        /**
         * 校验密码策略
         */
        pwdStrategyCheck: function (encodePwd) {
          var me = this;
          yufp.service.request({
            url: backend.uaaService + '/api/passwordcheck/checkpwd', // 校验密码策略
            method: 'POST',
            data: {
              sysId: yufp.session.logicSys.id,
              pwd: encodePwd,
              userId: me.pwdform.tempUserId,
              passwordType: '2'
            },
            callback: function (code, message, response) {
              if (code == 0 && response.code === '10100001') {
                yufp.service.request({
                  url: backend.appOcaService + '/api/adminsmuser/resetpwd',
                  method: 'POST',
                  data: JSON.stringify({
                    userId: me.pwdform.tempUserId,
                    password: encodePwd,
                    updateUser: yufp.session.userId
                  }),
                  callback: function (code, message, response) {
                    if (code === 0) {
                      me.$message({
                        message: me.$t('sysUserManager.mmxgcg')
                      }, 'success');
                      me.pwdform.dialogVisible = false;
                    } else {
                      me.$message({
                        message: me.$t('sysUserManager.mmxgsbqzs'),
                        type: 'warning'
                      });
                      return;
                    }
                  }
                });
              } else {
                me.$message({ message: response.message, type: 'warning' });
                return false;
              }
            }
          });
        },
        encodePassword: function (pwd) {
          var encrypt = new JSEncrypt();
          encrypt.setPublicKey(yufp.util.getRSAPublicKey());
          return encrypt.encrypt(pwd);
        }
      },
      mounted: function () {
        var me = this;
        yufp.lookup.bind('DATA_STS', function (data) {
          me.stsOptions = data;
        });
      }

    });
  };

  // 消息处理
  exports.onmessage = function (type, message) {

  };

  // page销毁时触发destroy方法
  exports.destroy = function (id, cite) {

  };
});
